package com.wangle.dao;

import java.io.UnsupportedEncodingException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import com.pro.bean.Card_Group;
import com.pro.bean.Groups;
import com.pro.bean.Info;
import com.dao.DBConnection;

public class CardGroupImpl {

	//ɾ�����С����Ϣ��������ݿ��ﻹ��
	
	public boolean deletecard(Info info){
		boolean flag=true;
		Connection conn=null;
		try {
			conn=DBConnection.getConnection();
			PreparedStatement stmt=null;
			stmt=conn.prepareStatement("delete from Info where cardid=?");
			stmt.setInt(1,info.getCardid());
			stmt.executeUpdate();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return flag;
	}
	
	public ArrayList<Info> querycard(String groupname,boolean allquery){
		
		Connection conn = null;
		try{
		conn = DBConnection.getConnection();
		} catch (SQLException e1) {
		e1.printStackTrace();
		}
		ArrayList<Info> cardlist=new ArrayList<Info>();//��������Ҫ����ݷ�װ��ArrayList��
		
		ResultSet rs=null;
		PreparedStatement stmt = null;
		try {
		if(allquery){

			//��ѯ����
			//System.out.println("asdf"+groupname+"");//�ж��Ƿ����querycard

		stmt=conn.prepareStatement("select cg.cardid,i.cmp,i.firstname,g.prgroupid from " +
		"groups g,card_group cg,info i where g.groupid=cg.groupid and cg.cardid=i.cardid and g.groupname='"+groupname+"';");
			
			rs=stmt.executeQuery();		  
	   }
		while(rs.next()){
			Info info=new Info();
			
			info.setCardid(Integer.valueOf(rs.getString("cardid")));
			info.setCmp(rs.getString("cmp"));
			info.setFirstName(rs.getString("firstname"));
			cardlist.add(info);
			
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}/*finally{
			
		}*/
		return cardlist;
	}
}
